package com.whmall.service.crm.provider;

import com.whmall.component.entity.dto.OperatorReqDTO;
import com.whmall.component.entity.dto.PageReqDTO;
import com.whmall.component.entity.dto.PageRspDTO;
import com.whmall.service.crm.api.SupplierReviewApi;
import com.whmall.service.crm.entity.dto.supplierreview.*;
import com.whmall.service.crm.module.supplierreview.SupplierReviewQueryCriteria;
import com.whmall.service.crm.module.supplierreview.SupplierReviewService;
import com.whmall.service.crm.module.supplierreview.SupplierReviewViewBuilder;
import com.whmall.service.crm.module.supplierreview.SupplierUserReviewTagManager;
import lombok.RequiredArgsConstructor;
import org.apache.dubbo.config.annotation.DubboService;

import java.util.List;
import java.util.Map;

/**
 * SupplierReviewProvider
 *
 * @author alex
 * @since 2021/1/18
 */
@RequiredArgsConstructor
@DubboService(interfaceClass = SupplierReviewApi.class)
public class SupplierReviewProvider implements SupplierReviewApi {
    private final SupplierReviewService supplierReviewService;
    private final SupplierReviewViewBuilder viewBuilder;
    private final SupplierUserReviewTagManager supplierUserReviewTagManager;

    @Override
    public Long create(OperatorReqDTO requester, CreateSupplierReviewReqDTO request) {
        return supplierReviewService.create(requester, request);
    }

    @Override
    public void update(OperatorReqDTO requester, Long reviewId, UpdateSupplierReviewReqDTO request) {
        supplierReviewService.update(requester, reviewId, request);
    }

    @Override
    public void remove(OperatorReqDTO requester, Long reviewId) {
        supplierReviewService.remove(requester, reviewId);
    }

    @Override
    public void syncTagStatistics() {
        supplierReviewService.syncTagStatistics();
    }

    @Override
    public List<SupplierReviewTagCategoryRspDTO> finaAllTagCategory(boolean includeTags) {
        return viewBuilder.buildAllTagCategory(includeTags);
    }

    @Override
    public List<SupplierReviewTagRspDTO> findAllTag() {
        return viewBuilder.buildAllTag();
    }

    @Override
    public Map<String, List<SupplierUserReviewTagDTO>> findAllUserTag() {
        return supplierUserReviewTagManager.findAll();
    }

    @Override
    public List<SupplierUserReviewTagDTO> findListUserTag() {
        return supplierUserReviewTagManager.findList();
    }

    @Override
    public PageRspDTO<SupplierReviewRspDTO> findReviewPageByQueryCriteria(PageReqDTO pageRequest, SupplierReviewQueryCriteria criteria) {
        return viewBuilder.buildReviewPage(pageRequest, criteria);
    }

    @Override
    public List<SupplierReviewTagStatisticsRspDTO> findReviewTagStatsByCompanyId(Long companyId, boolean includeTagInfo) {
        return viewBuilder.buildReviewTagStats(companyId, includeTagInfo);
    }

    @Override
    public Map<Long, List<SupplierReviewTagStatisticsRspDTO>> findReviewTagStatisticsByCompanyIds(List<Long> companyIds) {
        return viewBuilder.findReviewTagStatisticsByCompanyIds(companyIds);
    }

    @Override
    public Map<Long, Long> countByBusinessId(List<Long> businessIds, List<Integer> businessTypes, List<Integer> pageSources) {
        return supplierReviewService.countByBusinessId(businessIds, businessTypes, pageSources);
    }

}
